package org.ecloud.redis.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("app")
public class AppConfig {

	private String appid = "eroad";
	private String prefix = "ecloud";
	private String version = "1.0";
	public String getAppid() {
		return appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	public String getPrefix() {
		return prefix;
	}
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getRedisPrefix(){
		StringBuilder builder = new StringBuilder();
		
		builder.append(appid).append(":");
		builder.append(prefix).append(":");
		builder.append(version);
		
		return builder.toString();
	}
	public String getRedisKey(String ... originKeys){
		StringBuilder builder = new StringBuilder();
		
		builder.append(getRedisPrefix()).append(":");
		if(null != originKeys){
			for(String originKey : originKeys){
				builder.append(originKey).append(":");
			}
		}
		
		builder.setLength(builder.length() - 1);
		
		return builder.toString();
	}
	
}
